<?php
	//动态表
	
	class feed{
		var $db;
		var $table;
		var $pages;
		var $page; /*当前是第几页*/
	
		function __construct()
		{
			global $db, $M, $MODEL;
			$this->db = &$db;
			$this->table = DB_PRE.'feed';	
		}
	
		function feed()
		{
			$this->__construct();
		}
		
		function listinfo($where = '', $page = 1, $pagesize = 20)
		{
			$where = $where ? " WHERE $where " : '';
			$page = max(intval($page), 1);
			$offset = $pagesize*($page-1);
			$limit = " LIMIT $offset, $pagesize";
			
			
			$data = $this->db->select("SELECT count(*) AS `count` FROM `$this->table` $where");
			$number = count($data);
			unset($data);
			
			
			$this->pages = pages($number, $page, $pagesize);
			$this->page = $page;
			$array = array();
			$result = $this->db->select("SELECT * FROM `$this->table` $where ORDER BY `addtime` DESC $limit");
			return $result;
		}
		
		
		function add($module,$field,$value){
			global $_userid;
			if(!method_exists($this,$module)) return false;
			
			$data = $this->db->get_one("SELECT * FROM ".DB_PRE."$module WHERE `$field` = '$value'");
			$array['module'] = $module;
			$array['field'] = $field;
			$array['value'] = $value;
			$array['userid'] = $_userid;
			$array['addtime'] = TIME;
			$array['message'] = method_exists($this,$module) ? $this->$module($data) : '';
			
			
			$info = $this->db->get_one("SELECT * FROM $this->table WHERE `module`='$module' AND `field` = '$field' AND `value`='$value'");
			if($info){
				$this->db->update($this->table,$array," `module`='$module' AND `field` = '$field' AND `value`='$value' ");
			}
			else{
				$this->db->insert($this->table,$array);
			}
		}
		
		function blog($data){
			extract($data);
			return "<a target=\"_blank\" href=\"".url("?module=space&userid=$userid")."\">".nickname($userid)."</a>发布了一篇日志<br/><b><a target=\"_blank\" href=\"".url($url)."\">$title</a></b><br/>".str_cut($content,255);
		}
		
		function tweet($data){
			extract($data);
			return "<a target=\"_blank\" href=\"".url("?module=space&userid=$userid")."\">".nickname($userid)."</a>：{$description}";
		}
		
		function group_topic($data){
			extract($data);
			return "<a target=\"_blank\" href=\"".url("?module=space&userid=$userid")."\">".nickname($userid)."</a>：发布了一个小组话题<br/><b><a target=\"_blank\" href=\"".url($url)."\">$title</a></b><br/>".str_cut($content,255);
		}
		
		function wiki($data){
			extract($data);
			return "<a target=\"_blank\" href=\"".url("?module=space&userid=$userid")."\">".nickname($userid)."</a>：发布了一个百科<br/><b><a target=\"_blank\" href=\"".url($url)."\">$title</a></b><br/>".str_cut($content,255);
		}
		
		function edit(){
		
		}
		
		function delete(){
			
		}
	}
?>